import Vue from "vue";
import VueRouter from "vue-router";

import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: "/",
      name: "home",
      redirect: "/films",
      component: HomeView,
      children: [
        {
          path: "films",
          name: "films",
          // component: () => import("@/views/HomeFilmsView.vue"),
          component: () => import("@/views/films"),
          meta: {
            title: "电影",
          },
        },
        {
          path: "cinemas",
          name: "cinemas",
          // component: () => import("@/views/HomeCinemasView.vue"),
          component: () => import("@/views/cinemas"),
          meta: {
            title: "影院",
          },
        },
        {
          path: "demo",
          name: "demo",
          // component: () => import("@/views/HomeCinemasView.vue"),
          component: () => import("@/views/demo"),
          meta: {
            title: "Demo",
          },
        },
        {
          path: "center",
          name: "center",
          component: () => import("@/views/HomeCenterView.vue"),
          meta: {
            title: "我的",
          },
        },
      ],
    },
    {
      path: "/login",
      name: "login",
      // component: () => import("@/views/LoginView.vue"),
      component: () => import("@@/login"),
      meta: {
        title: "登录",
      },
    },
    {
      path: "/register",
      name: "register",
      // component: () => import("@/views/RegisterView.vue"),
      component: () => import("@@/register"),
      meta: {
        title: "注册",
      },
    },
    {
      path: "/city",
      name: "city",
      component: () => import("@/views/city"),
      meta: {
        title: "选择城市",
      },
    },
    {
      path: "/film/:id",
      name: "film",
      component: () => import("@/views/FilmDetailView.vue"),
      meta: {
        title: "详情",
      },
    },
  ],
});

router.beforeEach((to, from, next) => {
  // 设置页面的 title
  const title = to.meta.title;
  document.title = title;

  next();
});

export default router;
